/*
 * @Author: cpu_code
 * @Date: 2020-06-26 18:09:00
 * @LastEditTime: 2020-06-26 19:00:05
 * @FilePath: \c_course\linear_list\mul_array.c
 * @Gitee: https://gitee.com/cpu_code
 * @CSDN: https://blog.csdn.net/qq_44226094
 */ 
#include <stdio.h>

//多维数组与数组指针的练习
int main(void) 
{
	int i, j, k;
	int str[2][3][4] = {
							{
								{1, 2, 3, 4},\
								{5, 6, 7, 8},\
								{9, 10, 11, 12}
							},\
							{
								{13, 14, 15, 16},\
								{17, 18, 19, 20},\
								{21, 22, 23, 24}
							}
						};

	int (*p1)[3][4] = str;
	int *p2 = str;
	int **p3 = str;
	int ***p4 = str;

	printf("\n(*p1)[3][4] : \n");
	for (i = 0; i < 24; i++)
	{
		printf("%d ",*( *( *(p1) ) + i ) );
	}

	printf("\n *p2 : \n");
	for (i = 0; i < 24; i++)
	{
		printf("%d ", *(p2 + i) );
	}

	printf("\n**p3 :\n");
	for (i = 0; i < 24; i++)
	{
		printf("%d ", *(p3 + i) );
		//printf("%d ",*(*(*(p3)) + i)); //段错误
		//printf("%d ",***(p3 + i)); //段错误
	}
	
	printf("\n***p4 : \n");
	for (i = 0; i < 24; i++)
	{
		printf("%d ", *(p4 + i) );
		//printf("%d ",*(*(*(p4)) + i)); //段错误
		//printf("%d ",***(p4 + i)); //段错误
	}

	printf("\n指针下标法访问:\n");
	for (i = 0; i < 2; i++)
	{
		for (j = 0; j < 3; j++)
		{
			for (k = 0; k < 4; k++)
			{
				printf("%d ", p1[i][j][k]);
			}
		}
	}

	printf("\n");

  return 0;
}

/*

(*p1)[3][4] : 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 
 *p2 : 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 
**p3 :
1 3 5 7 9 11 13 15 17 19 21 23 1469720544 1469720544 1469720544 1469720544 1469720912 0 4199392 1364111515 0 1469720920 262144 4198722 
***p4 : 
1 3 5 7 9 11 13 15 17 19 21 23 1469720544 1469720544 1469720544 1469720544 1469720912 0 4199392 1364111515 0 1469720920 262144 4198722 
指针下标法访问:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 

*/